<?php

// +---------------------------------------------+
// |     Copyright  2010 - 2018 InterPhoto       |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+


include('includes/InterPhoto.Core.php');

CheckAccess('allowlogin');

$action = ForceIncomingString('action', 'displayimages');


$smarty = new InterPhoto;

@set_time_limit(600);


if($action == 'deleteimages' AND $userinfo['allowdelete'])
{
	$deleteimageids = ForceIncomingArray('deleteimageids');

	for($i = 0; $i < count($deleteimageids); $i++){
		DeleteImageById (ForceInt($deleteimageids[$i]), $userinfo['userid']);
	}

	$success = $sys_langs['deletefinished'];
	$action = 'displayimages';
}elseif($action == 'deleteimages' AND !$userinfo['allowdelete']){
	$errortitle = $langs['delete'].$langs['image'].$sys_langs['error'];
	$errors = $sys_langs['noaccessdelete'];
	$action = 'displayimages';
}


if($action == 'displayimages')
{
	$page = ForceIncomingInt('p', 1);
	$NumPerPage = 10;

	$start = $NumPerPage * ($page-1);
	$getimages = $DB->query("SELECT i.imageid, i.actived, i.path, i.filename, i.title, i.viewcount, i.downloadcount, i.created, c.title AS categorytitle FROM " . TABLE_PREFIX . "images i LEFT JOIN  " . TABLE_PREFIX . "categories c ON (c.categoryid = i.categoryid) WHERE i.userid = '$userinfo[userid]' ORDER BY i.actived ASC, i.imageid DESC LIMIT $start,$NumPerPage");
	$maxrows = $DB->query_first("SELECT COUNT(i.imageid) AS value FROM " . TABLE_PREFIX . "images i LEFT JOIN  " . TABLE_PREFIX . "categories c ON (c.categoryid = i.categoryid) WHERE  i.userid = '$userinfo[userid]' ");
	$images = $DB->getrows($getimages);

	$totalpages = ceil($maxrows['value'] / $NumPerPage);

	$noactiveimages = $DB->query_first("SELECT COUNT(imageid) AS value FROM " . TABLE_PREFIX . "images WHERE actived =0 AND userid = '" . $userinfo['userid'] . "'");

	$smarty->assign('noactiveimages', $noactiveimages['value']);

	$smarty->assign('pagelist', Iif($totalpages>1, GetPageList('mydesk.images.php', $totalpages, $page, 10), ''));
	$smarty->assign('images', $images);
	$smarty->assign('totalimages', $maxrows['value']);
}


//Always needing
$pagenav = '<a href="'.GetUrl('index.php').'">'.$langs['home'].'</a> '.$langs['nav'].' <a href="'.GetUrl('mydesk.php').'">'.$langs['mydesk'].'</a> '.$langs['nav'].' <a href="'.GetUrl('mydesk.images.php').'">'.$langs['manage'].$langs['my'].$langs['image'].'</a>';
$smarty->assign('pagenav', $pagenav);
$smarty->assign('userinfo', $userinfo);
$smarty->assign('pagetitle', $langs['manage'].$langs['my'].$langs['image'] . ' - ' .$mainsettings['siteTitle']);

$smarty->interPlay('mydesk.images.tpl');

?>